<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<style type="text/css">
table tr td ul li {height:30px; line-height:30px; display:block; border: solid 1px #ccc; 
	margin:0px 0px 2px 0px;
	padding: 0px 0px 0px 3px;}
.num {display:block; float:right; padding:0px 7px; margin-right:7px;}
table tr td{padding:7px 3px;}
table tr.slt { background:#d7d7d7;}
.pmenu, .pmenu span {padding:0px 7px;}
.print{display:block; padding:0px 12px;}
a:hover.print{color:#fff;}
.cbx {width:380px;}
#ajaxData table {margin-top:31px;}
div.time {font-size:10px;}
div.time p{margin:0px; paddin:0px; height:18px;}
</style>
<script type="text/javascript">
$(function() {
	$( "#s" ).datepicker({
		dateFormat:'yy-mm-dd'
		
	});
	$( "#e" ).datepicker({
		dateFormat:'yy-mm-dd'
		
	});
	var pids = $('.print').find('input[type=hidden][name=pid]').each(function(){
		var bid = $(this).val();
		if(bid == undefined) {
			alert(bid);
			return ;
		}
		var txt = '';
		txt += '<div class="pmenu"><a href="###" onclick=printBill("'+bid+'",false)><span>直接打印</span></a></div>';
		txt += '<div class="pmenu"><a href="###" onclick=printBill("'+bid+'",true)><span>打印单价</span></a></div>';
		$(this).parent().powerFloat({
			html: txt
		});
	});
});
function printBill(blid, unit) {
	$.get('/a/ajax/sell/print?blid=' + blid + "&unit=" + unit, function(data){
		var succeed = $.parseJSON(data).succeed;
		if(!succeed) {
			alert("打印失败！请检查打印机网络是否正常！");
		}
	});
}
// 格力空调安装卡插件
function Gree() {
	var dt/*弹出层内容*/, bg/*透明背景*/, _this;
	_this = this;
	// 隱藏列表
	function hide() {
		aju.removeAll([dt,bg,$('.tip-yellow')]);
		$('#ajaxClose').remove();
	};
	function tip(o, msg) {
		$(o).poshytip({
			content: function(){return msg},
			showOn:'hover',
			className: 'tip-yellow',
			alignTo: 'target',
			alignX: 'right',
			alignY: 'center',
			showTimeout:0,
			hideTimeout:3000,
			offsetX: 0,
			offsetY: 5
		});
	};
	this.init = function() {
		$('td ul').find('li').each(function(o) {
			var txt = $(this).html();
			var iskt = txt.indexOf('格力')!=-1 && txt.indexOf('空调')!=-1;
			if(iskt) {
				var tmp = $(this).attr('id');
				txt = '<a href="###" onclick=gree.showForm("'+tmp+'")><span>打印安装卡</span></a>';
				tip($(this).find('a'),txt);
			}
		});
		$(document).bind('keydown', function(event){
			if (event.keyCode == KEY.ESC) {
				hide();
			}
		});
	};
	this.showForm = function(tmp) {
		var blid = tmp.substring(3, tmp.lastIndexOf('_'));
		var gid = tmp.substring(tmp.lastIndexOf('_')+1);
		var url = '/a/ajax/plugins/gree/installForm';
		$.ajax({
			url:url,
			data:{gid:gid,blid:blid},
			type:'GET',
			success:function(data){
				bg = aju.ajaxBg(function() {
					aju.setOffsetDown(20);
					aju.setOffsetRight(10);
					dt = aju.ajaxData().css('width','80%').css('height','auto');
					dt.html(data);
					aju.positionCenter(dt);
					// 显示关闭按钮并绑定关闭时间
					aju.ajaxClose(dt).click(function(){
						hide();
					});
					// bind print event
					$('#printCreeCard').click(function(){
						doPrint();
					});
					$('.tip-yellow').remove();
					//
					$('#innerCode').focus();
					$( "#buyDate" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$( "#installDate" ).datepicker({
						dateFormat:'yy-mm-dd'
						
					});
					$(document).bind('keydown', function(event){
						//alert(event.keyCode)
						if($('#printCreeCard').is(':focus')) {
							if (event.keyCode == KEY.ENTER) {
								doPrint();
							}
						} else {
							if (event.keyCode == KEY.ENTER 
									|| event.keyCode == KEY.RETURN) 
							{
								$('#outerCode').focus();
								//event.keyCode = KEY.TAB;
							}
						}
					});
				});
			}
		});
	};
	function doPrint() {
		$('#printCreeCard').attr('disabled','disabled');
		var goodsName = $('#goodsName').val();
		var customerName = $('#customerName').val();
		var innerCode = $('#innerCode').val();
		var outerCode = $('#outerCode').val();
		var address = $('#address').val();
		var tel = $('#tel').val();
		var buyDate = $('#buyDate').val();
		var installDate = $('#installDate').val();
		var receiptCode = $('#receiptCode').val();
		var url = '/a/plugins/gree/installCard/print';
		$.ajax({
			type:'POST',
			url:url,
			data:{customerName:customerName
				,goodsName:goodsName
				,innerCode:innerCode
				,outerCode:outerCode
				,address:address
				,tel:tel
				,buyDate:buyDate
				,installDate:installDate
				,receiptCode:receiptCode},
			success:function(data){
				$('#printCreeCard').removeAttr('disabled');
				alert("内容已输出到打印机！");
				hide();
			}
		});
	};
}
var gree = new Gree();
$(function(){
	gree.init();
	$("#q").focus();
	$("#s").keyup(function(){
		var len = $(this).val().length;
		var val = $(this).val()+'-';
		switch(len) {
		case 4:
			$(this).val(val);
		case 7:
			$(this).val(val);
		}
	});
	$("#e").keyup(function(){
		var len = $(this).val().length;
		var val = $(this).val()+'-';
		switch(len) {
		case 4:
			$(this).val(val);
		case 7:
			$(this).val(val);
		}
	});
	//
	var nav_1 = '';
	nav_1 += '<div><a href="/a/sell/list?ick=false"><span>欠款</span></a></div>';
	nav_1 += '<div><a href="/a/sell/list?ick=true"><span>已清</span></a></div>';
	nav_1 += '<div><a href="/a/sell/list"><span>全部</span></a></div>';
	$('#isReturnMenu').powerFloat({
		width: '56px'
		, eventType: 'hover'
		, html: nav_1
		, fontSize: '12px'
	});
});
</script>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="list">
<div class="listnav">
<div class="cbx">
<c:set var="today" value="today" />
<c:set var="yestoday" value="yestoday" />
<c:set var="bfyestoday" value="bfyestoday" />
<c:set var="month" value="month" />
<c:set var="week" value="week" />
<span><a <c:if test="${empty d && empty s}">class="fcs" </c:if>href="/a/sell/list">全部</a></span>
<span><a <c:if test="${d == today}">class="fcs" </c:if>href="?d=today">今天</a></span>
<span><a <c:if test="${d == yestoday}">class="fcs" </c:if>href="?d=yestoday">昨天</a></span>
<span><a <c:if test="${d == bfyestoday}">class="fcs" </c:if>href="?d=bfyestoday">前天</a></span>
<span><a <c:if test="${d == week}">class="fcs" </c:if>href="?d=week">本周</a></span>
<span><a <c:if test="${d == month}">class="fcs" </c:if>href="?d=month">本月</a></span>
</div>
<form action="/a/sell/search" method="get">
开始时间：<input type="text" id="s" name="s" value="${s}" style="width:80px;" class="input"/>
&nbsp;&nbsp;
结束时间：<input type="text" id="e" name="e" value="${e}" style="width:80px;" class="input"/>
&nbsp;&nbsp;
关键词：<input type="text" id="q" name="q" value="${q}" style="width:100px;" class="input"/>
<input type="submit" name="" value="<fmt:message key="message.find.sure" />" />
</form>
</div>
<table>
<thead>
<tr>
<th><span class="num">数量</span>品牌/种类/型号/规格</th>
<th><fmt:message key="jsp.sell.list.price"/></th>
<th><fmt:message key="jsp.sell.list.price.realpay"/></th>
<th class="trigger" id="isReturnMenu"><a href="###">
<c:if test="${ick==true}">已清</c:if><c:if test="${ick==false}">欠款</c:if><c:if test="${ick==null}">账款</c:if> 
<b></b></a></th>
<th><fmt:message key="jsp.sell.list.time"/></th>
<th><fmt:message key="message.customer"/></th>
<th><fmt:message key="message.print"/></th>
<th><fmt:message key="message.return.goods"/></th>
</tr>
</thead>
<tbody>
<c:if test="${empty billVOList}">
<tr>
<td></td>
<td>暂无数据...</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</c:if>
<c:forEach var="item" items="${billVOList}" varStatus="s">
<tr class='<c:if test="${s.index%2==0}">slt</c:if><c:if test="${item.isReturn}"> deleted</c:if>'>
<td>
<ul>
<c:forEach var="voItem" items="${item.itemList}">
<li<c:if test="${voItem.isReturn}"> class='deleted'</c:if> id="li_${item.id}_${voItem.goods.id}">
<span class="num">${voItem.number}</span>
<a href="../batch/list?cid=${voItem.category.id}&bid=${voItem.brand.id}&gid=${voItem.goods.id}">
${voItem.brand.name}${voItem.category.name}${voItem.goods.name} (${voItem.payables})
</a>
</li>
</c:forEach>
<c:if test="${!empty item.memo}">
<span class="em">${item.memo}</span>
</c:if>
</td>
<td>${item.payables}</td>
<td>${item.realPayables}</td>
<td id="isChecked_${item.id}">
<c:if test="${!item.isReturn}">
<c:if test="${item.isChecked}">
<span class="paymentClear">清</span>
</c:if>
<c:if test="${!item.isChecked}">
<span class="paymentOwe"><a href="###" onclick="javascript:payment.showForm('${item.id}')">欠</a></span>
</c:if>
</c:if>
</td>
<td>
<div class="time">
<p><fmt:formatDate pattern="yy-MM-dd" value="${item.addTime}" /></p>
<p><fmt:formatDate pattern="hh:mm:ss" value="${item.addTime}" /></p>
</div>
</td>
<td>
<a href="../sell/list?tid=${item.town.id}">${item.town.name}</a>
<a href="../sell/list?vid=${item.village.id}">${item.village.name}</a>
<a href="../sell/list?cid=${item.customer.id}">
${item.customer.name}
</a>
<span class="em">${item.customer.mobile}</span>
</td>
<td><a href="javascrit:;" class="print"><input type="hidden" name="pid" value="${item.id}"/>打印</a></td>
<td><a href="./return?id=${item.id}&backURL=${backURL}">退货</a></td>
</tr>
</c:forEach>
</tbody>
</table>
${pagination}
    <c:if test="${STAT_VIEW}">
        <div style="margin:0px 0px 11px 0px; padding:3px 3px 0px 7px; background:#f6f6f6;">
            成本：${sumPurchase}
            &nbsp;&nbsp;
            销售：${sumRealPayables}
            &nbsp;&nbsp;
            毛利：<fmt:formatNumber value="${sumRealPayables-sumPurchase}" pattern="#,###,###,###.##"/>
            &nbsp;&nbsp;
            流水：<fmt:formatNumber value="${inOutMoney}" pattern="#,###,###,###.##"/>
            &nbsp;&nbsp;
            总共：<fmt:formatNumber value="${inOutMoney+sumRealPayables-sumPurchase}" pattern="#,###,###,###.##"/>
        </div>
    </c:if>
<div>
</div>
</div>
<div class="sidebarMenu">
<c:if test="${SELL_MODIFY}">
<ul>
<li><a href="/a/sell/form">新增销售</a></li>
</ul>
</c:if>
</div>
    <%@ include file="../store/sidebar.jsp" %>
<!--  -->
</div>
</div>
</body>
</html>